package main.www.wonderfuldata.com;

import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;


public class testJDBC02 {

    public static void main(String args[]){
       try {

           //   利用 反射 进行 driver  的实例化
           String className = "com.mysql.cj.jdbc.Driver";
           Class clazz = Class.forName(className);
           Driver driver = (Driver) clazz.newInstance();

           //url
           String url = "jdbc:mysql://localhost:3306/Carry111";

           //Properties提供用户名和密码
           Properties info = new Properties();
           info.setProperty("user", "root");
           info.setProperty("password", "root2020");

           //调取driver 的connert 进行连接
           Connection conn = driver.connect(url, info);

           System.out.println(conn);

       } catch (SQLException e) {
           e.printStackTrace();
       } catch (ClassNotFoundException e) {
           e.printStackTrace();
       } catch (InstantiationException e) {
           e.printStackTrace();
       } catch (IllegalAccessException e) {
           e.printStackTrace();
       }
    }
}
